<template>
  <div class="detail">
    <div class="top">
      <img
        class="logo"
        @click="goHome"
        style="cursor: pointer"
        src="../../assets/logos.png"
      />
    </div>
    <div class="info">
      <div class="sch-top">
        <div class="logo">
          <img class="logo-img" :src="schoolObj.logoUrl" />
        </div>
        <div class="right">
          <div class="sch-name">
            <span>{{ schoolObj.schoolName }}</span>
            <span class="major"
              >{{ schoolObj.majorName }}({{ schoolObj.majorCode }})</span
            >
            <span class="major">{{ schoolObj.learningStyleName }}</span>
          </div>
          <div class="item">
            <span class="collegeName">{{ schoolObj.collegeName }}</span>
          </div>
          <div class="item">
            <img class="image" src="../../assets/images/addr.svg" />
            <span>{{ schoolObj.provinceName }}</span>
          </div>
          <div class="tags">
            <div class="ele" v-for="ele in schoolObj.schoolTags" :key="ele">
              {{ ele }}
            </div>
          </div>
          <div class="sch-button">
            <div>
              <div class="item">
                <img class="image" src="../../assets/images/phone.svg" />
                <span>学校电话: {{ schoolObj.contactRsp?.dh }}</span>
              </div>
              <div class="item">
                <img class="image" src="../../assets/images/mail.svg" />
                <span>电子邮箱: {{ schoolObj.contactRsp?.yx }}</span>
              </div>
              <div class="item">
                <img class="image" src="../../assets/images/net.svg" />
                <span>学校网址: {{ schoolObj.contactRsp?.wz }}</span>
              </div>
            </div>
            <div class="button-left">
              <el-button type="success" round @click="editSchool">
                编辑</el-button
              >
            </div>
          </div>
        </div>
      </div>
      <div class="bottom">
        <ul>
          <li
            :class="{ active: ele.value === active }"
            v-for="ele in tabList"
            :key="ele.value"
            @click="clickTab(ele)"
          >
            {{ ele.label }}
          </li>
        </ul>
      </div>
      <img class="bg" src="../../assets/images/bg.png" />
      <img class="rg" src="../../assets/images/bg.png" />
    </div>
    <div class="con">
      <component
        :is="activeCom"
        :majorId="majorId.majorOutRelationId"
        ref="childRef"
      ></component>
    </div>
    <el-dialog
      v-model="editDialog"
      title="编辑学校信息"
      width="500px"
      :before-close="handleClose"
    >
      <div class="upload">
        <el-form
          ref="formRef"
          :model="formData"
          class="demo-ruleForm"
          status-icon
        >
          <el-form-item label="学校标签" prop="schoolTags">
            <el-checkbox-group v-model="formData.schoolTags">
              <el-checkbox label="985" value="985" />
              <el-checkbox label="211" value="211" />
              <el-checkbox label="双一流" value="双一流" />
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="学校电话" prop="dh">
            <el-input v-model="formData.dh" />
          </el-form-item>
          <el-form-item label="电子邮箱" prop="yx">
            <el-input v-model="formData.yx" />
          </el-form-item>
          <el-form-item label="学校网址" prop="wz">
            <el-input v-model="formData.wz" />
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="editDialog = false">取消</el-button>
          <el-button type="primary" @click="confirmEdit">确认</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import { ref, onMounted, reactive } from "vue";
import { useRoute, useRouter } from "vue-router";
import EnrollEdit from "./component/EnrollEdit.vue";
import ExamScopeEdit from "./component/ExamScopeEdit.vue";
import RecruitStudentEdit from "./component/RecruitStudentEdit.vue";
import ScoreEdit from "./component/ScoreEdit.vue";
import { schoolDetail, correctMajorInfo } from "@/api/api";
import { decrypt } from "@/utils/parseDate";
import { ElMessage } from "element-plus";
import { useStore } from "vuex";
const store = useStore();
const route = useRoute();
const router = useRouter();

// 当前激活tab
const active = ref(0);
const activeCom = ref(EnrollEdit);
// 专业id
const majorId = reactive({
  majorOutRelationId: route.query.majorOutRelationId,
});
// 学校信息
const schoolObj = ref({
  contactRsp: {},
  schoolTags: [],
});
// tab列表
const tabList = [
{
    label: "录取名单",
    value: 0,
    component: EnrollEdit,
  },
  {
    label: "分数分析",
    value: 1,
    component: ScoreEdit,
  },
  {
    label: "招生人数",
    value: 2,
    component: RecruitStudentEdit,
  },
  {
    label: "考试范围",
    value: 3,
    component: ExamScopeEdit,
  },
];
// tab 点击
function clickTab(el) {
  active.value = el.value;
  activeCom.value = el.component;
}

// 获取学校详情
async function getSchoolDetail() {
  try {
    const result = await schoolDetail({
      majorOutRelationId: majorId.majorOutRelationId,
    });
    const res = JSON.parse(decrypt(result));
    console.log(res);
    if (res.status === 0) {
      schoolObj.value = res.result;
    }
  } catch (e) {
    goHome();
  }
}
function goHome() {
  router.push({
    name: "school",
  });
}
function editSchool() {
  formData.value = {
    schoolTags: schoolObj.value.schoolTags,
    dh: schoolObj.value.contactRsp.dh,
    yx: schoolObj.value.contactRsp.yx,
    wz: schoolObj.value.contactRsp.wz,
  };
  editDialog.value = true;
}
const editDialog = ref(false);
function handleClose() {
  editDialog.value = false;
}
const formData = ref({});
const dataScholl = ref({});
async function confirmEdit() {
  console.log(dataScholl.value);
  dataScholl.value = {
    gradSchoolRsp: {
      contactRsp: {
        dh: formData.value.dh,
        wz: formData.value.wz,
        yx: formData.value.yx,
      },
      schoolTags: formData.value.schoolTags,
      majorOutRelationId: majorId.majorOutRelationId,
    },
  };
  console.log(dataScholl.value);
  const result = await correctMajorInfo(dataScholl.value);
  const deRes = JSON.parse(decrypt(result));
  console.log(deRes);
  if (deRes.status === 0) {
    ElMessage.success("编辑成功!");
    editDialog.value = !editDialog.value;
  } else {
    ElMessage.warning("编辑失败!");
  }
}
onMounted(() => {
  getSchoolDetail();
});
</script>
<style lang="less" scoped>
::v-deep .intention .el-card__header {
  padding: 10px !important;
}
::v-deep .intention .el-card__body {
  padding: 10px !important;
}
.ml10 {
  margin-left: 10px;
}
.ml20 {
  margin-left: 20px;
}
.ml30 {
  margin-left: 30px;
}
.mt5 {
  margin-top: 5px;
}
.mb10 {
  margin-bottom: 10px;
}
.mb20 {
  margin-bottom: 20px;
}
.mb30 {
  margin-bottom: 30px;
}
.mt10 {
  margin-top: 10px;
}
.mt20 {
  margin-top: 20px;
}
.mt30 {
  margin-top: 30px;
}
.mt40 {
  margin-top: 40px;
}
.pd20 {
  padding: 0 30px;
}
.fl-start-center {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.fl-center {
  display: flex;
  justify-content: center;
  align-items: center;
}
.fl-space-between-center {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.intention {
  ::v-deep .el-dialog__body {
    padding: 10px 20px 0 !important;
  }
}
.unlock {
  ::v-deep .el-dialog__body {
    padding: 0 !important;
  }
  ::v-deep .el-dialog__header {
    padding: 0 !important;
    padding-bottom: 0 !important;
    margin-right: 0 !important;
  }
  ::v-deep .el-dialog {
    background-color: transparent !important;
    box-shadow: 0 0 0 transparent !important;
  }
  .unlock-content {
    position: relative;
    width: 670px;
    height: 686px;
    img {
      width: 100%;
      height: 100%;
    }
    .unlock-main {
      position: absolute;
      top: 0;
      left: 0;
      width: 650px;
      height: 100%;
      padding: 0 10px 10px;
    }
    .no-inherit {
      position: absolute;
      top: 10px;
      right: 10px;
      font-size: 22px;
      z-index: 9;
    }
    .unlock-vip {
      width: 109px;
      height: 94px;
      position: absolute;
      top: -76px;
      right: 30px;
    }
    .unlock-title {
      height: 80px;
      line-height: 80px;
      text-align: center;
      font-size: 18px;
      font-weight: bold;
      color: #252752;
    }
    .unlock-bg {
      position: relative;
      background-color: #fff;
      border-radius: 10px;
      padding: 40px 0;
      height: 510px;
      display: flex;
      justify-content: center;
      align-items: center;
      .unlock-tips1 {
        font-size: 16px;
        font-weight: bold;
        color: #000;
        text-align: center;

        span {
          color: #ff6802;
          font-size: 22px;
        }
      }
      .unlock-step {
        background-color: #d9e9f7;
        padding: 20px;
        border-radius: 5px;
        margin-top: 30px;
        width: 395px;
        border: 1px dashed #7ec3fe;
        .unlock-step-top-title {
          background-color: #72beff;
          border-radius: 5px 5px 0 0;
          padding: 2px 0;
          width: 50px;
          text-align: center;
          text-align: center;
          color: #fff;
          font-style: italic;
          margin-left: 2px;
        }
        .unlock-step-top-content {
          border: 1px solid #878787;
          background-color: #fff;
          padding: 10px;
          border-radius: 3px;
          text-align: center;
          width: 170px;
          .unlock-step-top-code {
            width: 80px;
            height: 80px;
            background-color: #f8f5f5;
            border-radius: 5px;
          }
          .unlock-step-top-text {
            margin-left: 20px;
            font-size: 14px;
            color: #1d1d1d;
          }
        }
        .unlock-step-bottom-title {
          background-color: #72beff;
          border-radius: 5px 5px 0 0;
          padding: 2px 0;
          width: 50px;
          text-align: center;
          text-align: center;
          color: #fff;
          font-style: italic;
          margin-left: 4px;
        }
        .unlock-step-bottom-input {
          width: 300px;
          height: 40px;
        }
        .unlock-step-bottom-button {
          width: 80px;
          height: 36px;
          font-weight: bold;
          margin-left: 10px;
        }
      }
      .tips-title {
        font-weight: bold;
        font-size: 13px;
        color: #1d1d1d;
      }
      .tips-subtitle {
        font-size: 12px;
        margin-top: 5px;
        color: #1d1d1d;
      }
      .unlock-service {
        .unlock-service-code {
          display: flex;
          justify-content: center;
          align-items: center;
          img {
            background-color: #f8f5f5;
            width: 80px;
            height: 80px;
            border-radius: 5px;
          }
        }
        .unlock-service-title {
          text-align: center;
          font-size: 12px;
          color: #1d1d1d;
          margin-top: 10px;
        }
      }
    }
  }
}
.code-content {
  position: fixed;
  top: 30%;
  right: 45px;
  .code-img {
    display: flex;
    justify-content: center;
  }
  .code-text {
    // font-size: 13px;
    // color: 000;
    // text-align: center;
    margin-top: 10px;
  }
}
.detail {
  width: 1200px;
  margin: 0 auto;

  .top {
    margin-top: 30px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    //height: 50px;
    //line-height: 50px;
    img {
      width: 200px;
    }
    .el-button {
      margin-right: 20px;
    }
  }
  .info {
    padding: 36px 32px 0;
    position: relative;
    background: linear-gradient(131deg, #f60, #ffbb48);
    height: 295px;
    .sch-top {
      display: flex;
      align-items: center;
      .logo {
        padding: 13px;
        box-sizing: border-box;
        border-radius: 30px;
        width: 160px;
        height: 160px;
        background-color: #fff;
        .logo-img {
          width: 100%;
          height: 100%;
        }
      }
      .right {
        margin-left: 24px;

        flex: 1;
        .sch-name {
          display: flex;
          align-items: center;
          justify-content: flex-start;
          color: #fff;
          font-size: 26px;
          .wrong {
            margin-left: auto;
            display: inline-block;
            padding: 4px 12px;
            border: 1px solid #fff;
            border-radius: 14px;
            font-size: 12px;
            cursor: pointer;
          }
          .major {
            margin-left: 10px;
            font-size: 20px;
          }
        }
        .sch-button {
          display: flex;
          justify-content: flex-start;
          align-items: center;
          .button-left {
            margin-left: 50px;
          }
        }
        .item {
          margin: 5px 0;
          display: flex;
          align-items: center;
          height: 24px;
          .collegeName {
            font-size: 18px;
          }
          .image {
            margin-right: 5px;
            width: 18px;
            height: 18px;
          }
          span {
            font-size: 14px;
            color: #fff;
          }
        }
        .tags {
          display: flex;
          align-items: center;
          height: 50px;
          .ele {
            margin-right: 10px;
            box-sizing: border-box;
            border: 1px solid #fff;
            height: 30px;
            line-height: 24px;
            color: #fff;
            font-size: 14px;
            padding: 2px 13px;
            border-radius: 15px;
          }
        }
      }
    }
    .bottom {
      ul {
        margin-bottom: 0;
        display: flex;
        align-items: center;
      }
      .active {
        background-color: #fff;
        color: #ff7214;
      }
      li {
        margin-right: 10px;
        flex: 1 1;
        list-style: none;
        background: hsla(0, 0%, 100%, 0.3);
        color: #fff;
        text-align: center;
        height: 44px;
        line-height: 44px;
        cursor: pointer;
        z-index: 999;
        &:hover {
          background-color: #fff;
          color: #ff7214;
        }
      }
    }
    .bg {
      position: absolute;
      top: 0;
      left: 0;
      width: 210px;
      height: 210px;
      transform: rotate(180deg);
    }
    .rg {
      position: absolute;
      width: 210px;
      height: 210px;
      right: 0;
      bottom: 0;
    }
  }
  .con {
    padding: 32px 0;
    width: 100%;
  }
  .upload {
    .avatar-uploader {
      width: 100%;
      height: 100%;
      /deep/ .el-icon.avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        text-align: center;
      }
      /deep/ .el-upload {
        border: 1px dashed #8c939d !important;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
      }
    }
  }
}
</style>
